package com.zhang.service.impl;

import com.zhang.mapper.IShopMapper;
import com.zhang.pojo.ShopBean;
import com.zhang.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ShopServiceImpl implements IShopService{

    @Autowired
    private IShopMapper shopMapper;


    @Override
    public List<ShopBean> findByUserId(int userId) {
        return shopMapper.findByUserId(userId);
    }

    @Override
    public void del(int shopId) {
        shopMapper.del(shopId);
    }

    @Override
    public void add(int productId, int userId) {
        ShopBean byId = shopMapper.findById(productId, userId);
//        System.out.println("=====================>"+byId.getNum());
//        System.out.println("=====================>"+byId.getShopId());
        if (byId != null){
            int num = byId.getNum();
            num = num + 1;
            update(byId.getShopId(),num);
        }else {
            shopMapper.add(new ShopBean(productId,userId));
        }
    }

    @Override
    public void update(int shopId, int num) {
        shopMapper.update(shopId, num);
    }
}
